import logging
import functools
import time

# 配置日志记录
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

def repeat(n):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            # 记录开始时间
            start_time = time.time()  
            for i in range(n):
                result = func(i + 1, *args, **kwargs)  # 传递调用次数
            # 记录结束时间
            end_time = time.time()  
            elapsed_time = end_time - start_time  # 计算运行时间
            logging.info(f"Function {func.__name__} took {elapsed_time:.4f} seconds to run.")
            
            return result
        
        return wrapper
    return decorator

@repeat(n=10)
def hello_world(call_number, message):
    logging.info(f"Call {call_number}: {message}")

if __name__ == "__main__":
    hello_world("Hello world!")  # 传递消息
